package com.ruicar.afs.cloud.manage.common.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.manage.common.entity.ManageCaseType;
import com.ruicar.afs.cloud.manage.common.service.ManageCaseTypeService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: 维护修改意见
 */
@Slf4j
@RestController
@RequestMapping("/caseType")
@AllArgsConstructor
public class ManageCaseTypeController {
    private ManageCaseTypeService manageCaseTypeService;

    @ApiOperation(value = "查询")
    @PostMapping("/getCase")
    public IResponse getCase(@RequestParam("caseType") String caseType,@RequestParam("contractBusiness") String contractBusiness){
        return new IResponse().setData(manageCaseTypeService.list(Wrappers.<ManageCaseType>lambdaQuery()
                .eq(ManageCaseType::getCaseType, caseType)
                .eq(ManageCaseType::getContractBusiness, contractBusiness)));
    }

    @ApiOperation(value = "新增")
    @PostMapping("/saveCase")
    public IResponse saveCase(@RequestBody ManageCaseType manageCaseType){
        boolean result = manageCaseTypeService.save(manageCaseType);
        if(result){
            return new IResponse().setMsg("保存成功");
        }else{
            return new IResponse().fail("保存失败");
        }

    }

    @ApiOperation(value = "编辑")
    @PostMapping("/editCase")
    public IResponse editCase(@RequestBody ManageCaseType manageCaseType){
        boolean result = manageCaseTypeService.updateById(manageCaseType);
        if(result){
            return new IResponse().setMsg("保存成功");
        }else{
            return new IResponse().fail("保存失败");
        }
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/deleteCase")
    public IResponse deleteCase(@RequestParam("id") String id){
        boolean result = manageCaseTypeService.removeById(id);
        if(result){
            return new IResponse().setMsg("删除成功");
        }else{
            return new IResponse().fail("删除失败");
        }
    }
}
